package com.baichen;

import tech.medivh.classpy.classfile.bytecode.Instruction;

import java.util.Iterator;

public class PcRegister implements Iterable<Instruction>{

    private JvmStack stack;

    public PcRegister(JvmStack stack) {
        this.stack = stack;
    }

    @Override
    public Iterator<Instruction> iterator() {
        return new PcRegisterIterator();
    }

    class PcRegisterIterator implements Iterator<Instruction> {

        @Override
        public boolean hasNext() {
            return !stack.isEmpty();
        }

        @Override
        public Instruction next() {
            return stack.peek().getNextInstruction();
        }
    }
}
